<template>
  <div>
    <input type="file" accept=".json"  id="file" value="上传题目" />
    <input type="number" placeholder="请输入考试的年级" name="grade" v-model="testData.grade"/>
    <input type="text" placeholder="请输入考试的科目" name="grade" v-model="testData.course"/>
    <input type="datetime-local" placeholder="请输入考试的开始时间" name="test_time" v-model="testData.testTime"/>
    <input type="number" placeholder="请输入考试的时长" name="time" v-model="testData.time"/>
    <input type="button" value="提交" @click="upload" />
    <hr />

<!-- 添加题目文本框 -->
 <!--   题目：<input type="text" v-model="testData.title" name="sub_title" placeholder="请输入标题"/> <br />
    请选择题目类型：<select v-model="testData.type" style="width: 93px;">
      <option value="1">选择题</option>
      <option value="2">填空题</option>
      <option value="3">解答题</option>
    </select>
    <br />

   <ul id="con_list">
      <li>
          <input type="text" placeholder="请输入内容,例如A.12 B.12..."  />
          是否是正确答案：<select>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
      </li>

   </ul>

      提交按钮 -->
     <!-- <input type="button" value="提交" @click="submits" /> -->
  </div>
</template>

<script>
  import Vue from "vue";
  import $ from 'jquery';
  export default {
    name: "submanage",
    data: () => {
      return {
        info: "首页",
        testData:{
          grade:"",
          time:"1",
          testTime:new Date(),
          course:""
        }
      }
    },
    created:function(){
      var now = this.testData.testTime;
      // var nowStr = now.format("yyyy-MM-dd hh:mm:ss");
    },
    methods: {
      upload: function() {
        console.log(this.testData)
        var data = new FormData();
        data.append('files', document.getElementById("file").files[0]);
        data.append("grade",this.testData.grade);
        data.append("time",this.testData.time);
        data.append("testTime",this.testData.testTime);
        data.append("course",this.testData.course);
        // 向后台发起请求
        Vue.axios.post("http://localhost:8083/uploadTest", data, {
            headers: {
              'Content-Type': 'multipart/form-data'
            },
            withCredentials : true
          })
          .then(res => {
            console.log(res);
          })
          .catch(err => {
            console.log(err);
          })
      },
      dateformat:function(fmt){
        var o = {
          "M+" : this.getMonth()+1,                 //月份
          "d+" : this.getDate(),                    //日
          "h+" : this.getHours(),                   //小时
          "m+" : this.getMinutes(),                 //分
          "s+" : this.getSeconds(),                 //秒
          "q+" : Math.floor((this.getMonth()+3)/3), //季度
          "S"  : this.getMilliseconds()             //毫秒
        };

        if(/(y+)/.test(fmt)){
          fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        }

        for(var k in o){
          if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(
              RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
          }
        }
        return fmt;
      }
    },
    computed:{
      testTime:function(){
        console.log(this.getNowFormatDate(this.testTime));
        return this.getNowFormatDate(this.testTime);
      }
    }
  }
</script>

<style scoped="scoped">
  *{
    margin: 10px 0 0 0;
    padding: 0;
    list-style: none;
  }
</style>
